package com.iqismart.shorturl.websocket;

import com.iqismart.shorturl.config.UidHolder;

import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;

/**
 * 继承websocket配置类，将httpsession放入ServerEndpointConfig的map中
 * 从而达到使websocket对象可以访问到httpsession中的对象
 */
public class GetHttpSessionConfigurator extends ServerEndpointConfig.Configurator {

    /**
     * 重写修改握手方法
     * @param sec
     * @param request
     * @param response
     */
    @Override
    public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
        Long uid = UidHolder.getUid();
        if(uid == null || uid == 0){

        }
        sec.getUserProperties().put("uid",uid);
    }
}
